function LoadCtrl(obj) {
  var webofficeload;
  if (!!window.ActiveXObject || "ActiveXObject" in window) {
    webofficeload = '<object classid="clsid:FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5" codebase="http://www.officectrl.com/weboffice/WebOffice.ocx#Version=2019,1,7,3" id="WebOffice" width="100%" height="900" ><param name="BorderStyle" value="1"><param name="Menubar" value="1"><param name="Titlebar" value="1"><param name="Toolbars" value="1"></object>';
  } else {
    webofficeload = '<object id="WebOffice" CLSID="{FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5}" TYPE="application/x-itst-activex"  width=100% height=900></object>';
  }
  obj.innerHTML = webofficeload;
}


function ShowPage(access_token, type, fileId, fileName, pdfIdSignature, planningTitle,listCode,fileextend) {

  let path = "WebOfficeEdit";
  let strUrl;
  let pre = "WebOffice://|Officectrl|";//智能窗打开的固定参数

  let v = getBrowser();
  if (v == 1) {//当浏览器返回值为1时定义为使用智能窗方式打开网址

    strUrl = pre + window.location.protocol + '//' + window.location.host
        + process.env.VUE_APP_PUBLIC_PATH + '/#/' + path
        + '?access_token=' + access_token
        + '&type=' + type
        + '&fileId=' + fileId
        + '&fileName=' + (fileName ? fileName : '')
        + '&pdfIdSignature=' + (pdfIdSignature ? pdfIdSignature : '')
        + '&planningTitle=' + (planningTitle ? planningTitle : '')
        + '&listCode=' + (listCode ? listCode : '')
        + '&fileextend=' + (fileextend ? fileextend : '');
    window.open(strUrl, '_self');

  } else { //当浏览器返回值1以外的数据时采用传统方式打开网址

    strUrl = window.location.protocol + '//' + window.location.host
        + process.env.VUE_APP_PUBLIC_PATH + '/#/' + path
        + '?access_token=' + access_token
        + '&type=' + type
        + '&fileId=' + fileId
        + '&fileName=' + (fileName ? fileName : '')
        + '&pdfIdSignature=' + (pdfIdSignature ? pdfIdSignature : '')
        + '&planningTitle=' + (planningTitle ? planningTitle : '')
        + '&listCode=' + (listCode ? listCode : '')
        + '&fileextend=' + (fileextend ? fileextend : '');
    window.open(strUrl, '_blank');

  }
}

function getBrowser() {
  var Sys = {};
  var ua = navigator.userAgent.toLowerCase();
  var s;
  var ver;
  (s = ua.match(/edge\/([\d.]+)/)) ? Sys.edge = s[1] :
    (s = ua.match(/rv:([\d.]+)\) like gecko/)) ? Sys.ie = s[1] :
      (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
          (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
            (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
              (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
  if (Sys.edge) return 1;
  if (Sys.ie) return 1;
  if (Sys.firefox) return 1;
  if (Sys.chrome) {
    ver = Sys.chrome;
    ver.toLowerCase();
    var arr = ver.split('.');
    if (parseInt(arr[0]) > 43) {
      return 1;
    } else {
      return 0;
    }
  }
  if (Sys.opera) return 1;
  if (Sys.safari) return 1;
  return 1;
}

function WebSignature(strPic) {

  WebOffice.ActiveDocument.ActiveWindow.ActivePane.View.SeekView=9;
  WebOffice.ActiveDocument.Application.Selection.HeaderFooter.Shapes.AddPicture(strPic, false, true).Select();
  // WebOffice.ActiveDocument.Application.Selection.ShapeRange.PictureFormat.Brightness = 0.05;  //亮度
  // WebOffice.ActiveDocument.Application.Selection.ShapeRange.PictureFormat.Contrast = 0.15;  //对比度
  // WebOffice.ActiveDocument.Application.Selection.ShapeRange.Rotation = 315;       //旋转
  WebOffice.ActiveDocument.Application.Selection.ShapeRange.LockAspectRatio = false;
  WebOffice.ActiveDocument.Application.Selection.ShapeRange.Height = 35;   //图片的高和宽
  WebOffice.ActiveDocument.Application.Selection.ShapeRange.Width = 100;

  WebOffice.ActiveDocument.Application.Selection.ShapeRange.WrapFormat.AllowOverlap = true;
  WebOffice.ActiveDocument.Application.Selection.ShapeRange.WrapFormat.Side = 3;
  WebOffice.ActiveDocument.Application.Selection.ShapeRange.WrapFormat.Type = 3;

  WebOffice.ActiveDocument.Application.Selection.ShapeRange.RelativeHorizontalPosition =1;
  WebOffice.ActiveDocument.Application.Selection.ShapeRange.RelativeVerticalPosition =0;

  WebOffice.ActiveDocument.Application.Selection.ShapeRange.Left = 450;   //签章图片的相对位置
  WebOffice.ActiveDocument.Application.Selection.ShapeRange.Top = 600;
  WebOffice.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 0;
}

export {
  LoadCtrl, ShowPage, WebSignature
}
